﻿using System.Collections.ObjectModel;
using System.ComponentModel;
using System;

namespace WickedFlame.Core.Tools
{
	/// <summary>
	/// Types of shapes that can be contained in the drawing canvas
	/// </summary>
	//public enum ToolType { Line, SelectionTool, Rectangle, Ellipse, Polygon, SCurve, Curve, HardSelection, ColorPicker, Text, TrackerSelection, None };

	public class ToolControler : INotifyPropertyChanged
	{
		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		protected void NotifyPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}

		#endregion

		
		ObservableCollection<VectorTool> _toolsObserveableCollection;

		public ObservableCollection<VectorTool> Tools
		{
			get
			{
				if (_toolsObserveableCollection == null)
					_toolsObserveableCollection = new ObservableCollection<VectorTool>();
				return _toolsObserveableCollection;
			}
		}

		public void Add(VectorTool tool)
		{
			if (!Tools.Contains(tool))
			{
				Tools.Add(tool);
			}

			if (Tools.Count == 1)
			{
				SelectedTool = tool;
			}
		}

		VectorTool _selectedtool;
		public VectorTool SelectedTool
		{
			get
			{
				return _selectedtool;
			}
			set
			{
				_selectedtool = value;
				DrawingCanvas.InitializeNewTool(_selectedtool);
				NotifyPropertyChanged("SelectedTool");
				NotifyPropertyChanged("SelectedToolIndex");
			}
		}

		public int SelectedToolIndex
		{
			get
			{
				return Tools.IndexOf(SelectedTool);
			}
			set
			{
				SelectedTool = Tools[value];
			}
		}

		public Type ToolType
		{
			get
			{
				return SelectedTool.GetType();
			}
			set
			{
				foreach (VectorTool t in Tools)
				{
					if (t.GetType() == value)
					{
						SelectedTool = t;
						return;
					}
				}
			}
		}
	}
}
